package com.ycj.config;

import com.ycj.dao.CustomerPreferenceDao;
import com.ycj.dao.MovieCatalog;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import jakarta.annotation.Resource;
import jakarta.inject.Inject;
import jakarta.inject.Named;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;

@Log
@Configuration
@Order(1)
@ConditionalOnBean(ThirdConfig.class)
public class FirstConfig {

    @PostConstruct
    public void populateMovieCache() {
        // populates the movie cache upon initialization...
        log.info("populateMovieCache");
    }

    @PreDestroy
    public void clearMovieCache() {
        // clears the movie cache upon destruction...
        log.info("clearMovieCache");
    }
    private MovieCatalog movieCatalog;

    private String name;
//    @Resource
    @Inject
    @Named("movieCatalog2")
    private  final MovieCatalog<String> testmovieCatalog;


    public FirstConfig( MovieCatalog<String> movieCatalog,@Value("${jdbc.username}")String name) {
        log.info("FirstConfig 构造器");
        log.info("FirstConfig 构造器,name"+name);
        this.testmovieCatalog = movieCatalog;
        this.name =name;
    }
//    }  public FirstConfig(@Autowired @Qualifier("movieCatalog")MovieCatalog movieCatalog) {
//        log.info("FirstConfig 构造器");
//        this.testmovieCatalog = movieCatalog;
//    }

    @Bean
    @Autowired
    public CustomerPreferenceDao customerPreferenceDao(MovieCatalog<Integer> movieCatalog) {
        this.movieCatalog = movieCatalog;
        log.info(this.getClass().getName() + " {} init...");
        return new CustomerPreferenceDao();
    }

//    @Bean
//    @Autowired
//    public CustomerPreferenceDao customerPreferenceDao(@Qualifier("movieCatalog") MovieCatalog movieCatalog) {
//        this.movieCatalog = movieCatalog;
//        log.info(this.getClass().getName() + " {} init...");
//        return new CustomerPreferenceDao();
//    }
}
